home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / Origami / bindings / modeori-fun / autoterm.awk < prev    next >
Encoding:
AWK Script  |  1996-09-27  |  11.9 KB  |  467 lines

  1. BEGIN {
  2.    DQ=sprintf("%c",34)
  3.    terminal = ""
  4.    #{{{}}}
  5. #   {{{  init some arrays. for may work, even if no other values are stored
  6.    term_data_conflict["-"]="-"
  7.    alias["-"]="-"
  8.    term_data_leader["-"]="-"
  9. #   }}}
  10. #   {{{  define unknown and/or not used terminals
  11.    term_list["dumb"]="dumb"
  12.    term_list["print"]="dumb"
  13.    term_list["printer"]="dumb"
  14.    term_list["printerbox"]="dumb"
  15.    term_list["network"]="dumb"
  16.    term_list["ansi"]="dumb"
  17.    term_list["bussiplexer"]="dumb"
  18.    term_list["arpanet"]="dumb"
  19.    term_list["ethernet"]="dumb"
  20.    term_list["patchboard"]="dumb"
  21.    term_list["plugboard"]="dumb"
  22.    term_list["switch"]="dumb"
  23. #   }}}
  24. }
  25. #{{{  skip special terminals
  26. /^\(terminal \( *((sun)|(SUN)|(xterm)|(con80x25)|(console)) *\)/ {
  27.    print("special terminal "$2" skipped, using predefined values")
  28.    next
  29. }
  30. #}}}
  31. #{{{  start terminal
  32. /^\(terminal *\(.*\)$/ {
  33.    terminal=substr($2,2,length($2)-2)
  34.    if (term_list[terminal]!="") {
  35.       current_term_data="@if-using ()\n"
  36.    } else {
  37.       current_term_data=""
  38.    }
  39.    current_conflict=""
  40.    defined_alias=0
  41. #   {{{  init used keys and aliases
  42.    cntrl_h = 1
  43. #   {{{  tab
  44.    ok["tab"] = 1
  45.    alias["tab"] = "      (alias tab ( C-I ))"
  46.    name["tab"] = "tab-key"
  47. #   }}}
  48. #   {{{  rubout
  49.    ok["rubout"] = -1
  50.    alias["rubout"] = "-"
  51.    name["rubout"] = "del-key"
  52. #   }}}
  53. #   {{{  backspace
  54.    ok["backspace"] = -1
  55.    alias["backspace"] = "-"
  56.    name["backspace"] = "backs-key"
  57. #   }}}
  58. #   {{{  clreol
  59.    ok["clreol"] = -1
  60.    alias["clreol"] = "-"
  61.    name["clreol"] = "clreol-key"
  62. #   }}}
  63. #   {{{  delline
  64.    ok["dellint"] = -1
  65.    alias["delline"] = "-"
  66.    name["delline"] = "delline-key"
  67. #   }}}
  68. #   {{{  begin
  69.    ok["begin"] = -1
  70.    alias["begin"] = "-"
  71.    name["begin"] = "line-key"
  72. #   }}}
  73. #   {{{  end
  74.    ok["end"] = -1
  75.    alias["end"] = "-"
  76.    name["end"] = "line-key"
  77. #   }}}
  78. #   {{{  move
  79.    ok["move"] = -1
  80.    alias["move"] = "-"
  81.    name["move"] = "line-key"
  82. #   }}}
  83. #   {{{  copy
  84.    ok["copy"] = -1
  85.    alias["copy"] = "-"
  86.    name["copy"] = "line-key"
  87. #   }}}
  88. #   {{{  exit
  89.    ok["exit"] = -1
  90.    alias["exit"] = "-"
  91.    name["exit"] = "misc-key"
  92. #   }}}
  93. #   {{{  save
  94.    ok["save"] = -1
  95.    alias["save"] = "-"
  96.    name["save"] = "misc-key"
  97. #   }}}
  98. #   {{{  replace
  99.    ok["replace"] = -1
  100.    alias["replace"] = "-"
  101.    name["replace"] = "misc-key"
  102. #   }}}
  103. #   {{{  find
  104.    ok["find"] = -1
  105.    alias["find"] = "-"
  106.    name["find"] = "misc-key"
  107. #   }}}
  108. #   {{{  suspend
  109.    ok["suspend"] = -1
  110.    alias["suspend"] = "-"
  111.    name["suspend"] = "misc-key"
  112. #   }}}
  113. #   {{{  close
  114.    ok["close"] = -1
  115.    alias["close"] = "-"
  116.    name["close"] = "misc-key"
  117. #   }}}
  118. #   {{{  open
  119.    ok["open"] = -1
  120.    alias["open"] = "-"
  121.    name["open"] = "misc-key"
  122. #   }}}
  123. #   {{{  refresh
  124.    ok["refresh"] = -1
  125.    alias["refresh"] = "-"
  126.    name["refresh"] = "misc-key"
  127. #   }}}
  128. #   {{{  insert-char
  129.    ok["insert-char"] = -1
  130.    alias["insert-char"] = "-"
  131.    name["insert-char"] = "misc-key"
  132. #   }}}
  133. #   {{{  home
  134.    ok["home"] = -1
  135.    alias["home"] = "-"
  136.    name["home"] = "home-key"
  137. #   }}}
  138. #   {{{  home-down
  139.    ok["home-down"] = -1
  140.    alias["home-down"] = "-"
  141.    name["home-down"] = "home-key"
  142. #   }}}
  143. #   {{{  prev_page
  144.    ok["prev_page"] = -1
  145.    alias["pev_page"] = "-"
  146.    name["prev_page"] = "page-key"
  147. #   }}}
  148. #   {{{  next_page
  149.    ok["next_page"] = -1
  150.    alias["prev_page"] = "-"
  151.    name["next_page"] = "page-key"
  152. #   }}}
  153. #   {{{  up
  154.    ok["up"] = -1
  155.    alias["up"] = "-"
  156.    name["up"] = "cursor-key"
  157. #   }}}
  158. #   {{{  down
  159.    ok["down"] = -1
  160.    alias["down"] = "-"
  161.    name["down"] = "cursor-key"
  162. #   }}}
  163. #   {{{  left
  164.    ok["left"] = -1
  165.    alias["left"] = "-"
  166.    name["left"] = "cursor-key"
  167. #   }}}
  168. #   {{{  right
  169.    ok["right"] = -1
  170.    alias["right"] = "-"
  171.    name["right"] = "cursor-key"
  172. #   }}}
  173. #   {{{  help
  174.    ok["help"] = -1
  175.    alias["help"] = "-"
  176.    name["help"] = "help-key"
  177. #   }}}
  178. #   {{{  f1
  179.    ok["f1"] = -1
  180.    alias["f1"] = "-"
  181.    name["f1"] = "fx-key"
  182. #   }}}
  183. #   {{{  f2
  184.    ok["f2"] = -1
  185.    alias["f2"] = "-"
  186.    name["f2"] = "fx-key"
  187. #   }}}
  188. #   {{{  f3
  189.    ok["f3"] = -1
  190.    alias["f3"] = "-"
  191.    name["f3"] = "fx-key"
  192. #   }}}
  193. #   {{{  f4
  194.    ok["f4"] = -1
  195.    alias["f4"] = "-"
  196.    name["f4"] = "fx-key"
  197. #   }}}
  198. #   {{{  f5
  199.    ok["f5"] = -1
  200.    alias["f5"] = "-"
  201.    name["f5"] = "fx-key"
  202. #   }}}
  203. #   {{{  f6
  204.    ok["f6"] = -1
  205.    alias["f6"] = "-"
  206.    name["f6"] = "fx-key"
  207. #   }}}
  208. #   {{{  f7
  209.    ok["f7"] = -1
  210.    alias["f7"] = "-"
  211.    name["f7"] = "fx-key"
  212. #   }}}
  213. #   {{{  f8
  214.    ok["f8"] = -1
  215.    alias["f8"] = "-"
  216.    name["f8"] = "fx-key"
  217. #   }}}
  218. #   {{{  f9
  219.    ok["f9"] = -1
  220.    alias["f9"] = "-"
  221.    name["f9"] = "fx-key"
  222. #   }}}
  223. #   {{{  f10
  224.    ok["f10"] = -1
  225.    alias["f10"] = "-"
  226.    name["f10"] = "fx-key"
  227. #   }}}
  228.    keys=" "
  229.    use_keys=" "
  230. #   }}}
  231. #   {{{  init term data for this terminal
  232.    current_term_data=current_term_data "@if-using ( term-alias )\n%s   ( terminal ( %s )\n"
  233. #   }}}
  234. }
  235. #}}}
  236. #{{{  end terminal
  237. /^\)$/ {
  238.    if (terminal!="" && defined_alias) {
  239. #      {{{  end aliases
  240. #      {{{  get all aliases for current terminal
  241.       for ( i in alias )
  242.          if (alias[i]!="-")
  243.             if (ok[i])
  244.                current_term_data=current_term_data alias[i] "\n"
  245. #      }}}
  246. #      {{{  maybe add C-? as default rubout
  247.       if (ok["rubout"]==-1) {
  248.          alias["rubout"]="      (alias delete ( C-? ))"
  249.          current_term_data=current_term_data alias["rubout"] "\n"
  250.          ok["erubout"]=1
  251.          name["erubout"]="esc-del-key"
  252.          ok["erubout"]=1
  253.          alias["erubout"]=""
  254.       }
  255. #      }}}
  256. #      {{{  rubout defined, so define delete==rubout
  257.       if (ok["rubout"]==1)
  258.          current_term_data=current_term_data "      (alias delete ( $rubout ))\n"
  259. #      }}}
  260. #      {{{  add fx-keys
  261.       for (i=1;i<=10;i++)
  262.          current_term_data=current_term_data"      (alias f"i" ( C-[ "DQ"f "DQ (i%10)" ))\n"
  263. #      }}}
  264.       current_term_data=current_term_data "   )\n"
  265. #      }}}
  266. #      {{{  used keys
  267. #      {{{  mark keys as unhandled
  268.       for ( i in alias )
  269.          handled[name[i]]=""
  270. #      }}}
  271. #      {{{  get all use keys
  272.       for ( i in alias ) {
  273.          if (alias[i]!="-")
  274.             if (ok[i])
  275.                if (handled[name[i]]=="")
  276.                 { handled[name[i]]=1
  277.                   keys=keys name[i]" "
  278.                   use_keys=use_keys"use-"name[i]" "
  279.                 }
  280.          alias[i]="-"
  281.       }
  282. #      }}}
  283. #      {{{  maybe add C-H usage
  284.       if (cntrl_h) {
  285.          keys=keys"ctrl-h-key "
  286.          use_keys=use_keys"use-ctrl-h-key "
  287.       }
  288. #      }}}
  289. #      {{{  maybe add fx-handling
  290.       if (handled[name["f1"]]=="") {
  291.          keys=keys name["f1"]" "
  292.          use_keys=use_keys"use-"name["f1"]" "
  293.       }
  294. #      }}}
  295.       current_term_data=current_term_data "   @use ( "keys")\n@fi\n@if-using ( "use_keys") %s @fi\n"
  296. #      }}}
  297. #      {{{  store usage of current term and name of terminal
  298.       if (term_list[terminal]!="") {
  299.          current_term_data=current_term_data "@fi\n"
  300.          term_data_used[current_term_data]="un"
  301.          print("ignoring "term_list[terminal]" terminal ("terminal").")
  302.       } else {
  303.          term_list[terminal]="duplicate"
  304. #         {{{  add terminal name (leader or group)
  305.          if (term_data_leader[current_term_data]!="")
  306.             term_data_group[current_term_data]="" term_data_group[current_term_data] " " terminal
  307.          else
  308.             term_data_leader[current_term_data]=terminal
  309. #         }}}
  310. #         {{{  store conflicts for this term
  311.          if (current_conflict!="")
  312.             term_data_conflict[current_conflict]=term_data_conflict[current_conflict]" "terminal
  313. #         }}}
  314.       }
  315. #      }}}
  316.       count[current_term_data]++
  317.       terminal=""
  318.    }
  319. }
  320. #}}}
  321. #{{{  no terminal active, so skip line
  322. terminal=="" { next }
  323. #}}}
  324. #{{{  save alias
  325. /^ *\(alias/ {
  326.    alias[$2]="    "$0
  327. }
  328. #}}}
  329. #{{{  check needed keys
  330. #{{{  init critical and handle
  331. { critical=0
  332.   handle=0
  333. }
  334. #}}}
  335. #{{{  if used key, set handle to true
  336. $2~/^((rubout)|(backspace)|(up)|(down)|(left)|(right)|(f([123456789]|10)))$/ {
  337.    handle=1
  338. }
  339. $2~/^(((prev)|(next))_page)|(home)|(home-down)|(clreol)|(delline)|(begin)|(end)$/ {
  340.    handle=1
  341. }
  342. $2~/^(exit)|(save)|(refresh)|(open)|(close)|(suspend)|(find)|(replace)$/ {
  343.    handle=1
  344. }
  345. #}}}
  346. #{{{  esc critical char -> critical
  347. $4=="C-[" && $5~/^"[abcdefghijklmnopqrstuvwxyz0123456789+\-%]$/  {
  348.    if (handle)
  349.       current_conflict=current_conflict "   ;"$0" - "$5"\n"
  350.    critical=1
  351. }
  352. #}}}
  353. #{{{  esc <> critical char -> critical
  354. $4=="C-[" && $5~/^"[<>{}]$/ && $6~/^(("[abp])|(\)\)))$/ {
  355.    if (handle)
  356.       current_conflict=current_conflict "   ;"$0" - "$5"\n"
  357.    critical=1
  358. }
  359. #}}}
  360. #{{{  not esc ... -> critical
  361. $4~/C-[^[H^]/ || ($2!="backspace" && $4=="C-H") {
  362.    if (handle)
  363.       current_conflict=current_conflict "   ;"$0" - "$4"\n"
  364.    critical=1
  365. }
  366. #}}}
  367. #{{{  handled sequence starting with C-H -> no cntrl_h usage or critical
  368. handle!=0 && critical==0 && $4=="C-H" {
  369.    if ($2=="backspace")
  370.       cntrl_h=0
  371.    else
  372.       critical=1
  373. }
  374. #}}}
  375. handle!=0 {
  376.    if (ok[$2]==-1)
  377.       ok[$2]=1
  378.    if (ok[$2] && critical)
  379.       ok[$2]=0
  380.    if (ok[$2])
  381.       defined_alias=1
  382. #   {{{  maybe add esc-rubout
  383.    if ($2=="rubout" && ok[$2]) {
  384.       if ($4!="C-[") {
  385.          ok["erubout"]=1
  386.          alias["erubout"]="     ;esc-rubout can be used too"
  387.          name["erubout"]="esc-del-key"
  388.       }
  389.    }
  390. #   }}}
  391. }
  392. #}}}
  393. END {
  394.   print("; This file is generated by make(1), defining local terminals") >"autoterm"
  395.   for (i in term_data_leader)
  396.      if (i!="-") {
  397. #        {{{  print info for the group and collect names for terminal reference
  398.         print("{{{  "count[i]" "term_data_used[i]"used:"term_data_leader[i] term_data_group[i]) >"autoterm"
  399. #        {{{  gen termaliases
  400.         if (term_data_group[i]!="") {
  401.            termaliases="   ( termalias "term_data_leader[i]" ("term_data_group[i]" ) )\n"
  402.         } else {
  403.            termaliases=""
  404.         }
  405. #        }}}
  406. #        {{{  print aliases and used keys
  407.         printf(i,termaliases,term_data_leader[i],term_data_leader[i]) >"autoterm"
  408. #        }}}
  409.         print("}}}") >"autoterm"
  410.         termlist=termlist"@ref-start-item "term_data_leader[i] term_data_group[i]"\n@ref-end-item\n"
  411. #        }}}
  412.      }
  413. #  {{{  print conflicts
  414.   print("{{{  conflicts") >"autoterm"
  415.   for (i in term_data_conflict)
  416.      if (i!="-")
  417.         printf("{{{  %s\n%s}}}\n",term_data_conflict[i],i) >"autoterm"
  418.   print("}}}") >"autoterm"
  419. #  }}}
  420. #  {{{  print terminal reference-file
  421.   print("@{{{}}}") >"autoterm.r"
  422.   print("@{{{  autoterm-r") >"autoterm.r"
  423.   print("@{{{  which keyboards can be used") >"autoterm.r"
  424. #  {{{  standard terminals
  425.   print("This  version  works  with  (values  for  environment  variables  TERM  or") >"autoterm.r"
  426.   print("ORIGAMITERM):") >"autoterm.r"
  427.   print("") >"autoterm.r"
  428. #  {{{  xterm
  429.   print("@if-using ( xterm )") >"autoterm.r"
  430.   print("@if-using ( sun )") >"autoterm.r"
  431.   print("@ref-start-item xterm") >"autoterm.r"
  432.   print("If your keyboard/xterm is  reconfigured  to  match  a  standard  sun") >"autoterm.r"
  433.   print("keyboard, you can also use ORIGAMITERM=SUN. Therefor you have to map") >"autoterm.r"
  434.   print("the right keypad in the same way, a sun workstation does it.") >"autoterm.r"
  435.   print("See in the bindings source file  'modeori-fun/terms'  for  the  used") >"autoterm.r"
  436.   print("keysequences.") >"autoterm.r"
  437.   print("@fi") >"autoterm.r"
  438.   print("@ref-end-item") >"autoterm.r"
  439.   print("@if-using not( sun )") >"autoterm.r"
  440.   print("@ref-start-item xterm") >"autoterm.r"
  441.   print("@fi") >"autoterm.r"
  442.   print("@ref-end-item") >"autoterm.r"
  443.   print("@fi") >"autoterm.r"
  444. #  }}}
  445. #  {{{  sun
  446.   print("@if-using ( sun )") >"autoterm.r"
  447.   print("@ref-start-item sun") >"autoterm.r"
  448.   print("@ref-end-item") >"autoterm.r"
  449.   print("@fi") >"autoterm.r"
  450. #  }}}
  451. #  {{{  linux
  452.   print("@if-using ( linux )") >"autoterm.r"
  453.   print("@ref-start-item linux") >"autoterm.r"
  454.   print("@ref-end-item") >"autoterm.r"
  455.   print("@fi") >"autoterm.r"
  456. #  }}}
  457. #  {{{  collected terminals
  458.   print(termlist) >"autoterm.r"
  459. #  }}}
  460.   print("Not all mentioned terminals support all keys. Use 'describe-bindings'  for") >"autoterm.r"
  461.   print("a complete list of command bindings for your terminal.") >"autoterm.r"
  462. #  }}}
  463.   print("@}}}") >"autoterm.r"
  464.   print("@}}}") >"autoterm.r"
  465. #  }}}
  466. }
  467.